/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:DELL
 * Date:2025-07-11
 * Time:23:22
 */
public class Demo {//join等待
    public static void main(String[] args) {
        Thread t1 =new Thread(()->{
           for (int i=0;i<5;i++){
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
           }
            System.out.println("t1结束");
        });

        Thread t2 =new Thread(()->{
            for (int i = 0; i < 5; i++) {
                try {
                    t1.join();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("t2结束");
        });
        t1.start();
        t2.start();
        System.out.println("主线程结束！");
    }
}
